<template>
  <div class="result-card">
    <h4>预测结果</h4>
    <div class="threshold-wrap">
      <p>调整阈值</p>
      <a-slider :value="thresholdValue" :tooltip-open="false" :max="1" :min="0" :step="0.01" class="slider" @change="onSliderChange" />
      <span>{{ thresholdValue }}</span>
    </div>
    <div class="result-wrap">
      <header>
        <p>label</p>
        <p>置信度</p>
      </header>
      <ul class="result-list my-scrollbar">
        <li v-for="item in resultList" :key="item.id">
          <p>{{ item.label }}</p>
          <p :title="String(item.value)">{{ item.value }}</p>
        </li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
  export interface ResultOptions {
    id: string
    label: string
    value: string | number
  }

  export interface ResultCardProps {
    // 阈值
    thresholdValue?: number
    // 结果列表
    resultList?: ResultOptions[]
  }
  withDefaults(defineProps<ResultCardProps>(), {
    thresholdValue: 0
  })

  const emits = defineEmits<{
    (e: 'update:thresholdValue', value: number): void
    (e: 'changeThreshold', value: number): void
  }>()

  const onSliderChange = (value: any) => {
    emits('update:thresholdValue', value)
    emits('changeThreshold', value)
  }
</script>

<style lang="less" scoped>
  .result-card {
    display: flex;
    padding: 24px;
    width: 100%;
    height: 100%;
    flex-direction: column;

    > h4 {
      margin-bottom: 16px;
      font-size: 14px;
      color: rgba(16, 16, 20, 0.95);
      font-weight: 700;
      line-height: 22px;
    }

    .threshold-wrap {
      display: flex;
      align-items: center;
      padding: 8px 0;
      margin-bottom: 20px;
      height: 36px;
      font-size: 14px;
      color: rgba(25, 25, 48, 0.75);
      font-weight: 400;
      line-height: 22px;
      gap: 0 8px;

      > p {
        width: 80px;
      }

      .slider {
        flex: 1;
      }

      > span {
        width: 28px;
        font-size: 14px;
        text-align: end;
        color: rgba(25, 25, 48, 0.75);
        font-weight: 400;
        line-height: 22px;
      }
    }

    .result-wrap {
      overflow: hidden;
      width: 100%;
      background: #fff;
      border: 1px solid #e8e9eb;
      border-radius: 4px;
      flex: 1;

      > header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 16px;
        height: 38px;
        background: #f5f5f5;
        border-bottom: 1px solid #f2f3f5;
        gap: 0 4px;

        > p {
          font-size: 14px;
          color: rgba(17, 22, 31, 0.75);
          flex: 1;
          font-weight: 700;
          line-height: 22px;
        }
      }

      .result-list {
        overflow-y: auto;
        height: 100%;

        > li {
          display: flex;
          justify-content: space-between;
          align-items: center;
          padding: 0 16px;
          height: 40px;
          border-bottom: 1px solid #ebebeb;
          gap: 0 4px;

          > p {
            font-size: 14px;
            color: rgba(16, 16, 20, 0.95);
            flex: 1;
            line-height: 22px;
            .elliptical-1();
          }
        }
      }
    }
  }
</style>
